package com.enseirb.bdxmap.dao.parser;

import org.json.simple.JSONObject;

import com.enseirb.bdxmap.dao.dto.WifiMarkerDTO;

public class WifiMarkerParser extends AbstractMarkerParser<WifiMarkerDTO> {
	private static final String JSON_KEY_KEY = "cle";
	private static final String JSON_KEY_AREA = "secteur";
	private static final String JSON_KEY_NAME = "borne";
	private static final String JSON_KEY_LAT = "y_lat";
	private static final String JSON_KEY_LONG = "x_long";
	private static final String JSON_KEY_ID = "entityid";
	private static final String DEFAULT_NAME = "Wifi sans nom";
	
	public WifiMarkerParser() {
		super();
		json_key_id = JSON_KEY_ID;
		json_key_long = JSON_KEY_LONG;
		json_key_lat = JSON_KEY_LAT;
		json_key_name = JSON_KEY_NAME;
		default_marker_name = DEFAULT_NAME;
	}
	
	@Override
	public WifiMarkerDTO newServiceDTO() {
		return new WifiMarkerDTO();
	}

	@Override
	protected WifiMarkerDTO getCustomFieldsFromJson(
			WifiMarkerDTO wifiDTO, JSONObject wifiJson) {
		wifiDTO.area = getAreaFromJson(wifiJson);
		wifiDTO.key = getKeyFromJson(wifiJson);
		return wifiDTO;
	}

	private String getAreaFromJson(JSONObject wifiJson) {
		if(wifiJson.containsKey(JSON_KEY_AREA)) {
			return wifiJson.get(JSON_KEY_AREA).toString();
		} else {
			return "";
		}
	}

	private String getKeyFromJson(JSONObject wifiJson) {
		if(wifiJson.containsKey(JSON_KEY_KEY)) {
			return wifiJson.get(JSON_KEY_KEY).toString();
		} else {
			return "";
		}
	}
}
